const Router = require('@koa/router')
const router = new Router({ prefix: '/api/auth' })

const { userValidator, verifyUser, cryptPassword, verifyLogin, verifyToken } = require('../middleware/user.middleware')
const { handleGetUserinfo, login, register, resetPassword } = require('../controller/user.controller')
router.get('/_test', async (ctx, next) => {
  ctx.body = {
    code: 0,
    message: '测试成功'
  }
  await next()
})

router.get('/userinfo', verifyToken, handleGetUserinfo)
router.get('/userinfoById', handleGetUserinfo)
router.post('/login', userValidator, verifyLogin, login)
router.post('/register', userValidator, verifyUser, cryptPassword, register)
router.patch('/resetPassword', verifyToken, cryptPassword, resetPassword)

module.exports = router